#include "EditPreferences.h"
#include <wx/msgdlg.h>

// Creating XML documents
#include <wx/xml/xml.h>

// Mort System
#include "aux/MortSystem.h"

// Dir Dialog
#include <wx/dirdlg.h>

// File Dialog
#include <wx/filedlg.h>

//(*InternalHeaders(EditPreferences)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(EditPreferences)
const long EditPreferences::ID_STATICTEXT1 = wxNewId();
const long EditPreferences::ID_TEXTCTRL1 = wxNewId();
const long EditPreferences::ID_STATICTEXT2 = wxNewId();
const long EditPreferences::ID_TEXTCTRL2 = wxNewId();
const long EditPreferences::ID_STATICTEXT3 = wxNewId();
const long EditPreferences::ID_TEXTCTRL3 = wxNewId();
const long EditPreferences::ID_STATICTEXT4 = wxNewId();
const long EditPreferences::ID_SPINCTRL1 = wxNewId();
const long EditPreferences::ID_STATICTEXT5 = wxNewId();
const long EditPreferences::ID_SPINCTRL2 = wxNewId();
const long EditPreferences::ID_CHECKBOX1 = wxNewId();
const long EditPreferences::ID_STATICTEXT6 = wxNewId();
const long EditPreferences::ID_TEXTCTRL4 = wxNewId();
const long EditPreferences::ID_BUTTON3 = wxNewId();
const long EditPreferences::ID_CHECKBOX2 = wxNewId();
const long EditPreferences::ID_STATICTEXT7 = wxNewId();
const long EditPreferences::ID_TEXTCTRL5 = wxNewId();
const long EditPreferences::ID_BUTTON4 = wxNewId();
const long EditPreferences::ID_CHECKBOX3 = wxNewId();
const long EditPreferences::ID_CHECKBOX4 = wxNewId();
const long EditPreferences::ID_STATICTEXT8 = wxNewId();
const long EditPreferences::ID_SPINCTRL3 = wxNewId();
const long EditPreferences::ID_STATICTEXT9 = wxNewId();
const long EditPreferences::ID_SPINCTRL4 = wxNewId();
const long EditPreferences::ID_STATICTEXT10 = wxNewId();
const long EditPreferences::ID_SPINCTRL5 = wxNewId();
const long EditPreferences::ID_PANEL1 = wxNewId();
const long EditPreferences::ID_NOTEBOOK1 = wxNewId();
const long EditPreferences::ID_BUTTON1 = wxNewId();
const long EditPreferences::ID_BUTTON2 = wxNewId();
//*)

BEGIN_EVENT_TABLE(EditPreferences,wxScrollingDialog)
	//(*EventTable(EditPreferences)
	//*)
END_EVENT_TABLE()

EditPreferences::EditPreferences(wxWindow* parent, SkipfishConfigData *defaultProfile, wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(EditPreferences)
	wxBoxSizer* BoxSizer4;
	wxStaticBoxSizer* StaticBoxSizer2;
	wxBoxSizer* BoxSizer6;
	wxGridSizer* GridSizer4;
	wxBoxSizer* BoxSizer15;
	wxBoxSizer* BoxSizer5;
	wxBoxSizer* BoxSizer10;
	wxBoxSizer* BoxSizer7;
	wxBoxSizer* BoxSizer8;
	wxBoxSizer* BoxSizer13;
	wxStaticBoxSizer* StaticBoxSizer4;
	wxGridSizer* GridSizer5;
	wxBoxSizer* BoxSizer2;
	wxBoxSizer* BoxSizer11;
	wxBoxSizer* BoxSizer12;
	wxBoxSizer* BoxSizer14;
	wxGridSizer* GridSizer6;
	wxStaticBoxSizer* StaticBoxSizer3;
	wxGridSizer* GridSizer1;
	wxGridSizer* GridSizer3;
	wxBoxSizer* BoxSizer1;
	wxBoxSizer* BoxSizer9;
	wxStaticBoxSizer* StaticBoxSizer1;
	wxFlexGridSizer* FlexGridSizer1;
	wxBoxSizer* BoxSizer3;
	wxStaticBoxSizer* StaticBoxSizer5;
	wxGridSizer* GridSizer2;
	
	Create(parent, id, _("Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("id"));
	SetClientSize(wxSize(531,964));
	Move(wxDefaultPosition);
	FlexGridSizer1 = new wxFlexGridSizer(2, 1, 0, 0);
	FlexGridSizer1->AddGrowableCol(0);
	FlexGridSizer1->AddGrowableRow(0);
	Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
	Panel1 = new wxPanel(Notebook1, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	GridSizer1 = new wxGridSizer(5, 1, 0, 0);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Auth options"));
	GridSizer2 = new wxGridSizer(3, 1, 0, 0);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Username"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	BoxSizer2->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishUsernameTextCtrl = new wxTextCtrl(Panel1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
	BoxSizer2->Add(SkipfishUsernameTextCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer2->Add(BoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
	StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Password"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	BoxSizer3->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishPasswordTextCtrl = new wxTextCtrl(Panel1, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	BoxSizer3->Add(SkipfishPasswordTextCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer2->Add(BoxSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
	StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Custom Cookie"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	BoxSizer4->Add(StaticText3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishCustomCookieTextCtrl = new wxTextCtrl(Panel1, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
	BoxSizer4->Add(SkipfishCustomCookieTextCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer2->Add(BoxSizer4, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer1->Add(GridSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Crawl options"));
	GridSizer3 = new wxGridSizer(3, 1, 0, 0);
	BoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
	StaticText4 = new wxStaticText(Panel1, ID_STATICTEXT4, _("Max. depth"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
	BoxSizer5->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishMaxDepthSpinCtrl = new wxSpinCtrl(Panel1, ID_SPINCTRL1, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 0, _T("ID_SPINCTRL1"));
	SkipfishMaxDepthSpinCtrl->SetValue(_T("0"));
	BoxSizer5->Add(SkipfishMaxDepthSpinCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer3->Add(BoxSizer5, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
	StaticText5 = new wxStaticText(Panel1, ID_STATICTEXT5, _("Max. total request"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
	BoxSizer6->Add(StaticText5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishMaxTotalRequestSpinCtrl = new wxSpinCtrl(Panel1, ID_SPINCTRL2, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0, 100000000, 0, _T("ID_SPINCTRL2"));
	SkipfishMaxTotalRequestSpinCtrl->SetValue(_T("0"));
	BoxSizer6->Add(SkipfishMaxTotalRequestSpinCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer3->Add(BoxSizer6, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
	SkipfishDontDescendInto5xxCheckBox = new wxCheckBox(Panel1, ID_CHECKBOX1, _("Don\'t descend into into 5xx locations"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	SkipfishDontDescendInto5xxCheckBox->SetValue(false);
	BoxSizer7->Add(SkipfishDontDescendInto5xxCheckBox, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer3->Add(BoxSizer7, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer2->Add(GridSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer1->Add(StaticBoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer3 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Reporting options"));
	GridSizer4 = new wxGridSizer(2, 1, 0, 0);
	BoxSizer8 = new wxBoxSizer(wxHORIZONTAL);
	StaticText6 = new wxStaticText(Panel1, ID_STATICTEXT6, _("Write output to"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
	BoxSizer8->Add(StaticText6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishWriteOutputToTextCtrl = new wxTextCtrl(Panel1, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_TEXTCTRL4"));
	BoxSizer8->Add(SkipfishWriteOutputToTextCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfihBrowseButton = new wxButton(Panel1, ID_BUTTON3, _("Browse"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
	BoxSizer8->Add(SkipfihBrowseButton, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer4->Add(BoxSizer8, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
	SkipfishLogWarningsAboutMixedContentCheckBox = new wxCheckBox(Panel1, ID_CHECKBOX2, _("Log warnings about mixed content"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
	SkipfishLogWarningsAboutMixedContentCheckBox->SetValue(false);
	BoxSizer9->Add(SkipfishLogWarningsAboutMixedContentCheckBox, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer4->Add(BoxSizer9, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer3->Add(GridSizer4, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer1->Add(StaticBoxSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer4 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Dictionary options"));
	GridSizer5 = new wxGridSizer(3, 1, 0, 0);
	BoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
	StaticText7 = new wxStaticText(Panel1, ID_STATICTEXT7, _("Load wordlist"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
	BoxSizer10->Add(StaticText7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishLoadWordlistTextCtrl = new wxTextCtrl(Panel1, ID_TEXTCTRL5, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_TEXTCTRL5"));
	BoxSizer10->Add(SkipfishLoadWordlistTextCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishLoadWordlistBrowseButton = new wxButton(Panel1, ID_BUTTON4, _("Browse"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
	BoxSizer10->Add(SkipfishLoadWordlistBrowseButton, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer5->Add(BoxSizer10, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
	SkipfishDontLearnNewWordsForTheSiteCheckBox = new wxCheckBox(Panel1, ID_CHECKBOX3, _("Don\'t learn new words for the site"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX3"));
	SkipfishDontLearnNewWordsForTheSiteCheckBox->SetValue(false);
	BoxSizer11->Add(SkipfishDontLearnNewWordsForTheSiteCheckBox, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer5->Add(BoxSizer11, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
	SkipfishDontUpdateWordlistCheckBox = new wxCheckBox(Panel1, ID_CHECKBOX4, _("Don\'t update wordlist based on the scan"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
	SkipfishDontUpdateWordlistCheckBox->SetValue(false);
	BoxSizer12->Add(SkipfishDontUpdateWordlistCheckBox, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer5->Add(BoxSizer12, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer4->Add(GridSizer5, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer1->Add(StaticBoxSizer4, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer5 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Performance options"));
	GridSizer6 = new wxGridSizer(3, 0, 0, 0);
	BoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
	StaticText8 = new wxStaticText(Panel1, ID_STATICTEXT8, _("Max. Global TCP connections"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
	BoxSizer13->Add(StaticText8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishMaxGlobalTCPConnectionsSpinCtrl = new wxSpinCtrl(Panel1, ID_SPINCTRL3, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 0, _T("ID_SPINCTRL3"));
	SkipfishMaxGlobalTCPConnectionsSpinCtrl->SetValue(_T("0"));
	BoxSizer13->Add(SkipfishMaxGlobalTCPConnectionsSpinCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer6->Add(BoxSizer13, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer14 = new wxBoxSizer(wxHORIZONTAL);
	StaticText9 = new wxStaticText(Panel1, ID_STATICTEXT9, _("Max. consecutive HTTP fails"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT9"));
	BoxSizer14->Add(StaticText9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishMaxHTTPFailsSpinCtrl = new wxSpinCtrl(Panel1, ID_SPINCTRL4, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 0, _T("ID_SPINCTRL4"));
	SkipfishMaxHTTPFailsSpinCtrl->SetValue(_T("0"));
	BoxSizer14->Add(SkipfishMaxHTTPFailsSpinCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer6->Add(BoxSizer14, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer15 = new wxBoxSizer(wxHORIZONTAL);
	StaticText10 = new wxStaticText(Panel1, ID_STATICTEXT10, _("Total request timeout (sec.)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT10"));
	BoxSizer15->Add(StaticText10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SkipfishTotalRequestTimeoutSpinCtrl = new wxSpinCtrl(Panel1, ID_SPINCTRL5, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 0, _T("ID_SPINCTRL5"));
	SkipfishTotalRequestTimeoutSpinCtrl->SetValue(_T("0"));
	BoxSizer15->Add(SkipfishTotalRequestTimeoutSpinCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer6->Add(BoxSizer15, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer5->Add(GridSizer6, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	GridSizer1->Add(StaticBoxSizer5, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Panel1->SetSizer(GridSizer1);
	GridSizer1->Fit(Panel1);
	GridSizer1->SetSizeHints(Panel1);
	Notebook1->AddPage(Panel1, _("Skipfish"), false);
	FlexGridSizer1->Add(Notebook1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
	SaveButton = new wxButton(this, ID_BUTTON1, _("Save"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer1->Add(SaveButton, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	CancelButton = new wxButton(this, ID_BUTTON2, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	CancelButton->SetDefault();
	BoxSizer1->Add(CancelButton, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer1->Add(BoxSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->SetSizeHints(this);
	
	Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EditPreferences::OnSkipfihWriteOutputToBrowseButtonClick);
	Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EditPreferences::OnSkipfishLoadWordlistBrowseButtonClick);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EditPreferences::OnSaveButtonClick);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EditPreferences::OnCancelButtonClick);
	//*)

	// Load default values
	this->LoadDefaultProfileValuesIntoWidgets( defaultProfile );
}

EditPreferences::~EditPreferences()
{
	//(*Destroy(EditPreferences)
	//*)
}


void EditPreferences::OnCancelButtonClick(wxCommandEvent& event)
{
    this->Destroy();
}

void EditPreferences::OnSaveButtonClick(wxCommandEvent& event)
{
    wxString spinValue;

    wxXmlNode *root = new wxXmlNode( NULL, wxXML_ELEMENT_NODE, wxT("MortConf") );
    root->AddAttribute(wxT("version"), wxT("1"));

    wxXmlNode *child = NULL;
    wxXmlNode *parentConf = NULL;
    wxXmlNode *section = NULL;

    // Skipfish configuration
    parentConf = new wxXmlNode( root, wxXML_ELEMENT_NODE, wxT("Skipfish") );

    // Auth section
    section = new wxXmlNode( parentConf , wxXML_ELEMENT_NODE, wxT("Auth") );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("Username"));
    child->AddProperty( wxT("Value"), this->SkipfishUsernameTextCtrl->GetValue() );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("Password"));
    child->AddProperty( wxT("Value"), this->SkipfishPasswordTextCtrl->GetValue() );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("CustomCookie"));
    child->AddProperty( wxT("Value"), this->SkipfishCustomCookieTextCtrl->GetValue() );

    // Crawl section
    section = new wxXmlNode( parentConf , wxXML_ELEMENT_NODE, wxT("Crawl") );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("MaxDepth"));
    spinValue.Printf(wxT("%d"), this->SkipfishMaxDepthSpinCtrl->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("MaxTotalRequests"));
    spinValue.Printf(wxT("%d"), this->SkipfishMaxTotalRequestSpinCtrl->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("DontDescendInto5xxLocations"));
    spinValue.Printf(wxT("%d"), this->SkipfishDontDescendInto5xxCheckBox->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );


    // Reporting section
    section = new wxXmlNode( parentConf , wxXML_ELEMENT_NODE, wxT("Reporting") );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("WriteOutputTo"));
    child->AddProperty( wxT("Value"), this->SkipfishWriteOutputToTextCtrl->GetValue() );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("LogWarningsAboutMixedContent"));
    spinValue.Printf(wxT("%d"), this->SkipfishLogWarningsAboutMixedContentCheckBox->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    // Dictionary section
    section = new wxXmlNode( parentConf , wxXML_ELEMENT_NODE, wxT("Dictionary") );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("LoadWordlist"));
    child->AddProperty( wxT("Value"), this->SkipfishLoadWordlistTextCtrl->GetValue() );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("DontLearnNewWordsForTheSite"));
    spinValue.Printf(wxT("%d"), this->SkipfishDontLearnNewWordsForTheSiteCheckBox->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("DontUpdateWordlistBasedOnTheScan"));
    spinValue.Printf(wxT("%d"), this->SkipfishDontUpdateWordlistCheckBox->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    // Performance section
    section = new wxXmlNode( parentConf , wxXML_ELEMENT_NODE, wxT("Performance") );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("MaxGlobalTCPConnections"));
    spinValue.Printf(wxT("%d"), this->SkipfishMaxGlobalTCPConnectionsSpinCtrl->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("MaxHTTPFails"));
    spinValue.Printf(wxT("%d"), this->SkipfishMaxHTTPFailsSpinCtrl->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    child = new wxXmlNode( section, wxXML_ELEMENT_NODE, wxT("TotalRequestTimeout"));
    spinValue.Printf(wxT("%d"), this->SkipfishTotalRequestTimeoutSpinCtrl->GetValue() );
    child->AddProperty( wxT("Value"), spinValue );

    wxXmlDocument *doc = new wxXmlDocument();

    doc->SetRoot(root);

    if ( !MortSystem::CheckProfileDir() )
    {
        // Config Dir does not exists
        MortSystem::CreateProfileDir();
    }

    doc->Save( MortSystem::GetProfileDir() + wxT("default.xml") );

    this->Destroy();
}

void EditPreferences::OnSkipfihWriteOutputToBrowseButtonClick(wxCommandEvent& event)
{
    const wxString& dir = wxDirSelector(_("Choose a folder"));

    if ( !dir.empty() )
        this->SkipfishWriteOutputToTextCtrl->SetValue( dir );
}

void EditPreferences::OnSkipfishLoadWordlistBrowseButtonClick(wxCommandEvent& event)
{
    const wxString& file = wxFileSelector(_("Choose a wordlist file"));

    if ( !file.empty() )
        this->SkipfishLoadWordlistTextCtrl->SetValue( file );
}


void EditPreferences::LoadDefaultProfileValuesIntoWidgets( SkipfishConfigData *defaultProfile )
{
    // Load values into widgets

    // Skipfish Configuration
    this->SkipfishUsernameTextCtrl->SetValue( defaultProfile->username );
    this->SkipfishPasswordTextCtrl->SetValue( defaultProfile->password );
    this->SkipfishCustomCookieTextCtrl->SetValue( defaultProfile->customCookie );
    this->SkipfishMaxDepthSpinCtrl->SetValue( defaultProfile->maxDepth );
    this->SkipfishMaxTotalRequestSpinCtrl->SetValue( defaultProfile->maxTotalRequest );
    this->SkipfishDontDescendInto5xxCheckBox->SetValue( defaultProfile->dontDescendInto5xxLocations );
    this->SkipfishWriteOutputToTextCtrl->SetValue( defaultProfile->writeOutputTo );
    this->SkipfishLogWarningsAboutMixedContentCheckBox->SetValue( defaultProfile->logWarningsAboutMixedContent );
    this->SkipfishLoadWordlistTextCtrl->SetValue( defaultProfile->loadWordlist );
    this->SkipfishDontLearnNewWordsForTheSiteCheckBox->SetValue( defaultProfile->dontLearnNewWordForTheSite );
    this->SkipfishDontUpdateWordlistCheckBox->SetValue( defaultProfile->dontUpdateWordlistBaseOnTheScan );
    this->SkipfishMaxGlobalTCPConnectionsSpinCtrl->SetValue( defaultProfile->maxGlobalTCPConnections );
    this->SkipfishMaxHTTPFailsSpinCtrl->SetValue( defaultProfile->maxCosecutiveHttpFails );
    this->SkipfishTotalRequestTimeoutSpinCtrl->SetValue( defaultProfile->totalRequestTimeout );
}
